package com.sskj.cndragon.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.cndragon.bean.BankInfoBean;
import com.sskj.cndragon.bean.RateBean;
import com.sskj.cndragon.component.DaggerUserDataComponent;
import com.sskj.cndragon.http.HttpConfig;
import com.sskj.cndragon.ui.activity.RechargeActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;

import java.io.File;

public class RechargeActivityPresenter extends BasePresenter<RechargeActivity> {

    public void uploadFile(File file) {
        httpService.uploadFile(file)
                .tag(this)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<String>> response) {
                        HttpData body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.changeHead((String) body.getData());
                        } else {
                            ToastUtil.showShort(body.getMsg());
                        }
                    }
                });
    }

    public void getCrystalRate() {
        httpService.getCrystalRate()
                .tag(this)
                .execute(new JsonCallBack<HttpData<RateBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<RateBean>> response) {
                        HttpData<RateBean> body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.getRateOK(body.getData());
                        } else {
                            ToastUtil.showShort(body.getMsg());
                        }

                    }
                });
    }

    public void getBankInfo() {
        httpService.getBankInfo()
                .tag(this)
                .execute(new JsonCallBack<HttpData<BankInfoBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<BankInfoBean>> response) {
                        HttpData<BankInfoBean> body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.getBankInfoOK(body.getData());
                        } else {
                            ToastUtil.showShort(body.getMsg());
                        }
                    }
                });
    }

    public void recharge(String userID, String num, String fee, String mImagePath) {
        httpService.recharge(userID, num, fee, mImagePath)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.finish();
                        }
                    }
                });
    }
}
